import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath } from "node:url";

// https://vitejs.dev/config/

export default defineConfig(({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    base: env.VITE_APP_ENV === "production" ? "http://17.0.1.35:18902" : "/",
    plugins: [vue()],
    server: {
      host: "0.0.0.0",
      port: 7000,
      open: true,
      proxy: {
        "/api": {
          //  ws: true,
          target: "http://127.0.0.1:18902",
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/api/, ""),
        },
      },
    },
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          //用于在编译每个 Sass 文件之前插入一些额外的 Sass 代码
          additionalData: `@import "@/assets/styles/el-table.scss";
          @import "@/assets/styles/util.scss";`,
        },
      },
    },
  };
});
